﻿using TrackSystem.IO.Formula;

namespace TrackSystem.IO.Utils
{
    public class FormulaResult
    {
        /// <summary>
        /// 返回代码
        /// </summary>
        public int Code { get; set; }
        /// <summary>
        /// 成功标记
        /// </summary>
        public bool Success { get; set; }
        /// <summary>
        /// 返回信息
        /// </summary>
        public string? Message { get; set; }

        /// <summary>
        /// 返回数据
        /// </summary>
        public object? Data { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static FormulaResult Ok(object data, string msg="Success") => new()
        {
            Code = 200,
            Success = true,
            Message = msg,
            Data = data
        };

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static FormulaResult Ok(string msg = "Success") => new()
        {
            Code = 200,
            Success = true,
            Message = msg,
        };

        public static FormulaResult Fail(string msg, int code = 400) => new()
        {
            Code = code,
            Success = false,
            Message = msg
        };

        public static FormulaResult Fail(string msg, OperandDef data) => new()
        {
            Code = 400,
            Success = false,
            Message = msg,
            Data = data
        };

        public static FormulaResult New(bool bSucc, string msg, OperandDef? data = null) => new() { 
            Success = bSucc,
            Message = msg,
            Data = data ??= new OperandDef(),
            Code = bSucc ? 200 : 400
        };

    }

}
